﻿/*                              
   Copyright 2011 Nils Kopal, Christopher Krüger, Simone Sauer, Dennis Nolte, Uni Duisburg-Essen

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Sharebert.SearchLibrary
{
    /// <summary>
    /// A list of files, that a client offers.
    /// This list is sent to the index server.
    /// </summary>
    [Serializable]
    public struct FileOfferList
    {
        public FileOfferList(string clientIP, int clientPort, FileOffer[] list)
        {
            this.clientIP = clientIP;
            this.clientPort = clientPort;
            this.Files = list;
        }

        public FileOffer[] Files;

        public string clientIP;

        public int clientPort;
    }

    /// <summary>
    /// A specific file on the client.
    /// </summary>
    public struct FileOffer
    {
        public FileOffer(string name, long size)
        {
            this.Name = name;
            this.Size = size;
        }

        public string Name;

        public long Size;
    }

    /// <summary>
    /// A regular expression used to search the server database for files.
    /// This request is sent to the server.
    /// </summary>
    [Serializable]
    public struct SearchRequest
    {
        public SearchRequest(string regex)
        {
            this.Regex = regex;
        }

        public string Regex;
    }

    /// <summary>
    /// A list of files that a specific client offers.
    /// </summary>
    public struct SearchResult
    {
        public SearchResult(string clientIP, int clientPort, FileOffer[] offeringFiles)
        {
            this.ClientIP = clientIP;
            this.ClientPort = clientPort;
            this.OfferingFiles = offeringFiles;
        }

        public string ClientIP;

        public int ClientPort;

        public FileOffer[] OfferingFiles;
    }

    /// <summary>
    /// The resulting list of all clients with all their files, that match the search request.
    /// This list is used as response to a file search.
    /// </summary>
    [Serializable]
    public struct SearchResultList
    {
        public SearchResultList(SearchResult[] results)
        {
            this.ResultList = results;
        }

        public SearchResult[] ResultList;
    }
}
